package cn.cmcc.intertelecom.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.cmcc.intertelecom.bean.Department;
import cn.cmcc.intertelecom.bean.DepartmentExample;
import cn.cmcc.intertelecom.bean.UserExample;
import cn.cmcc.intertelecom.bean.DepartmentExample.Criteria;
import cn.cmcc.intertelecom.dao.DepartmentMapper;

@Service
public class DepartmentService {
	@Autowired
	private DepartmentMapper departmentMapper;
	
	/**
	 * 查询所有部门和其管理员
	 * @return
	 */
	public List<Department> selectAllDeptAndAdmin(){
		DepartmentExample example=new DepartmentExample();
		example.setOrderByClause("d.id");
		List<Department> list = departmentMapper.selectByExampleWithAdmin(example);
		return list;
	}

	/**
	 *  员工保存
     * 1. 支持jsr303
     * 2. 导入Hibernate-validator
	 * @param department
	 */
	public void saveDept(Department department) {
		departmentMapper.insertSelective(department);
		
	}

	public Department selectDeptById(Integer id) {
		
		return departmentMapper.selectByPrimaryKeyWithAdmin(id);
	}

	/**
	 * 更新部门数据
	 * @param department
	 */
	public void updateDept(Department department) {
		departmentMapper.updateByPrimaryKeySelective(department);
		
	}

	/**
	 * 批量删除部门
	 * @param ids
	 */
	public int deleteBatch(List<Integer> ids) {
		DepartmentExample example=new DepartmentExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdIn(ids);
		return departmentMapper.deleteByExample(example);
		
	}

	/**
	 * 删除部门
	 * @param deptIds
	 */
	public int deleteDept(int deptIds) {

		return departmentMapper.deleteByPrimaryKey(deptIds);
	}

	/**
	 * 查询所有部门信息
	 * @return
	 */
	public List<Department> selectAllDepts() {
		
		return departmentMapper.selectByExample(null);
	}
}
